//
//  MineFriendViewController.m
//  cityCar
//
//  Created by yao on 14-11-9.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "MineFriendViewController.h"
#import "MineFriendCell.h"
#import <SinaWeiboConnection/SSSinaWeiboUser.h>
#import "FriendDetailViewController.h"

@interface MineFriendViewController ()<UITableViewDataSource, UITableViewDelegate>

@property(nonatomic, retain)UITableView *myTableView;

@end

@implementation MineFriendViewController

- (void)dealloc
{
    [_friendArr release];
    [_myTableView release];
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setupView];
    
}

- (void)setupView
{
    // 屏幕宽和高
    CGFloat x = self.view.frame.size.width;
//    CGFloat y = self.view.frame.size.height;

    
    // 顶部View
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, x, 64)];
    headView.backgroundColor = [WebColor whiteSmoke];
    [self.view addSubview:headView];
    [headView release];
    
    // 标题
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake((x - 100) / 2, 15, 100, 50)];
    titleLabel.text = @"我的好友";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [headView addSubview:titleLabel];
    [titleLabel release];
    
    // 返回按钮
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(10, 25, 30, 30);
    [button setImage:[UIImage imageNamed:@"iconfont-fanhui.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    button.tintColor = [WebColor black];
    [headView addSubview:button];

    
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 64) style:UITableViewStylePlain];
    self.myTableView.backgroundColor = [WebColor white];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    self.myTableView.rowHeight = 70;
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.myTableView];
    [_myTableView release];
}

#pragma mark - tableView 协议
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.friendArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MineFriendCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reusefriend"];
    if (!cell) {
        cell = [[[MineFriendCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"reusefriend"] autorelease];
    }
    
    SSSinaWeiboUser *user = [self.friendArr objectAtIndex:indexPath.row];

    [cell.myImageView sd_setImageWithURL:[NSURL URLWithString:user.profileImage] placeholderImage:[UIImage imageNamed:@"NoPicture.png"]];
//    [cell.myImageView sd_setImageWithURL:[NSURL URLWithString:user.profileImage]];
    cell.titleLabel.text = user.nickname;
    cell.verifyReasonLabel.text = user.verifyReason;
    if (user.gender == 1) {
        cell.sexImageView.image = [UIImage imageNamed:@"girl.jpg"];
    } else if (user.gender == 0) {
        cell.sexImageView.image = [UIImage imageNamed:@"boy.jpg"];
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    SSSinaWeiboUser *user = [self.friendArr objectAtIndex:indexPath.row];
    FriendDetailViewController *friendVC = [[FriendDetailViewController alloc] init];
    friendVC.userUrl = user.url;
    [self presentViewController:friendVC animated:YES completion:^{
        
    }];
    
}


// 返回按钮
- (void)buttonClicked:(UIButton *)button
{
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.tabBarController.tabBar.hidden = NO;
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
